import { attr, SkillItem, sprite } from '../myinterface';
import { atkComputed } from '@/utils/attrComputed/index';
import * as _ from 'lodash';
import { skillUpdataSprite } from '../utils';

interface SkillItemClassInterface {
  mySprite: sprite;
  enemySprite: sprite;
  skillItem: SkillItem;
  play(): void;
}
//模板
// export class SkillItemClass implements SkillItemClassInterface {
//     constructor(curAttr: attr, otherAttr: attr, skillItem: SkillItem) {
//         this.curAttr = curAttr
//         this.otherAttr = otherAttr
//         this.skillItem = skillItem
//     }
//     curAttr;
//     otherAttr;
//     skillItem;
//     play() {
//         //伤害类
//         //对方状态
//         //恢复类
//         //我方状态
//     }
// }

export class SkillItemClass implements SkillItemClassInterface {
  constructor(
    public mySprite: sprite,
    public enemySprite: sprite,
    public skillItem: SkillItem,
  ) {
    this.mySprite = _.cloneDeep(mySprite);
    this.enemySprite = _.cloneDeep(enemySprite);
    this.skillItem = _.cloneDeep(skillItem);
  }
  play() {
    //计算伤害
    let atk = atkComputed(this.mySprite, this.skillItem);
    // console.log('mySprite', this.mySprite.skill);
    if (this.enemySprite.attr.currAttr.hp > atk) {
      this.enemySprite.attr.currAttr.hp -= atk;
      // console.log('内部classhp', this.enemySprite.attr.currAttr.hp, 'atk', atk);
    } else {
      this.enemySprite.attr.currAttr.hp = 0;
    }
    this.skillItem.count--;
    this.mySprite = skillUpdataSprite(this.skillItem, this.mySprite);
  }
}
